// snooze.c
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>

extern int errno;
unsigned int snooze(unsigned int secs);
void handler(int sig);

int main(int argc, char *argv[])
{
    unsigned int rest_seconds = 0;
    unsigned int secs = argv[1][0] - '0';


    if (signal(SIGINT, handler) == SIG_ERR)
    {
        fprintf(stderr, "signal error: %s\n", strerror(errno));
        exit(0);
    }

    rest_seconds = snooze(secs);
    printf("User hits crtl-c after %u seconds\n", secs - rest_seconds);

    return 0;
}

unsigned int snooze(unsigned int secs)
{
    int rest_seconds = sleep(secs);

    printf("Sleep for %u of %u seconds\n", secs - rest_seconds, secs);
    return rest_seconds;
}

void handler() {}